﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mmoss.orm;
using mmoss.configuration;
using mmoss.application.classes;

namespace mmoss.application
{
    public partial class frmAdminInventoryItem : Form
    {
        public frmAdminInventoryItem()
        {
            InitializeComponent();
            this.Load += new EventHandler(frmAdminInventoryItem_Load);
            dgInventoryItem.AutoGenerateColumns = false;
        }

        void frmAdminInventoryItem_Load(object sender, EventArgs e)
        {
            dgInventoryItem.NewRowNeeded += new DataGridViewRowEventHandler(dgInventoryItem_NewRowNeeded);

            //set combobox list
            cboCategory.DataSource = dbConn.db.InventoryItemTypes;
            cboCategory.ValueMember = "InventoryTypeID";
            cboCategory.DisplayMember = "InventoryTypeDesc";
        
            //add the type
            DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
            comboboxColumn.DataSource = dbConn.db.InventoryItemTypes;
            comboboxColumn.ValueMember = "InventoryTypeID";
            comboboxColumn.DisplayMember = "InventoryTypeDesc";
            comboboxColumn.HeaderText = "Type";
            comboboxColumn.DataPropertyName = "itemTypeID";
            dgInventoryItem.Columns.Add(comboboxColumn);


            //add the description
            DataGridViewTextBoxColumn textColumn = new DataGridViewTextBoxColumn();
            textColumn.DataPropertyName = "itemShortDesc";
            //textColumn.IsDataBound = true;
            dgInventoryItem.Columns.Add(textColumn);
            //bind data
            buildDataView();

        }

        void dgInventoryItem_NewRowNeeded(object sender, DataGridViewRowEventArgs e)
        {
            int i_loop = 0;   
        }
        private void buildDataView()
        {

            dgInventoryItem.DataSource = dbConn.db.InventoryItems.ToList();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //save list off
            InventoryItem l_item = new InventoryItem();
            l_item.itemLongDesc = txtItemName.Text;
            l_item.itemShortDesc = txtItemName.Text;
            l_item.InventoryItemType = ((InventoryItemType)cboCategory.SelectedItem);
            l_item.User = Default.CurrentUser;
            dbConn.db.InventoryItems.InsertOnSubmit(l_item);
            dbConn.db.SubmitChanges();
            buildDataView();
        }
    }
}
